<template>
  <div>
    <van-cell-group>
        <van-field
          v-model="password"
          label="密码"
          placeholder="请输入密码"
          autofocus
        />
      </van-cell-group>
      <div class="loginBtn">
        <van-button type="danger" :disabled='flag' round size="large" @click="register">完成</van-button>
      </div>
  </div>
</template>

<script>
import {doRegister} from '../../api/user'
export default {
    data () {
        return {
            password:''
        }
    },
    computed: {
        flag(){
            //密码强弱，最少6位，至少一位大写，1个字母，1个数组
            if (/^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])\S*$/.test(this.password)){
                return false  //红色可用
            } else {
                return true //暗色禁用
            }
        }
    },
    //连接接口完成注册，带两参数，再完成跳转到登录页面
    methods: {
      register(){
        doRegister({tel:localStorage.getItem("tel"),password:this.password}).then((res)=>{
          console.log(res);
          this.$router.push("/login")
        })
      }
    }
};
</script>

<style scoped>
.loginBtn {
  width: 90%;
  margin: 20px auto;
}
</style>